#include "processbar.h"

void Processbar1()
{
    char str[NUM];
    memset(str, 0, sizeof(str));
    char* lable = "-\\|/";
    int len = strlen(lable);
    
    int cnt = 0;
    while (cnt < NUM)
    {
        str[cnt] = STYLE;
        printf("[%-100s][%d%%][%c]\r", str, cnt, lable[cnt % len]);
        fflush(stdout);
        usleep(50000);

        ++cnt;
    }

    printf("\n");
}

void Processbar2(float cur, float total)
{
    char str[NUM];
    memset(str, 0, sizeof(str));
    char* lable = "-\\|/";
    int len = strlen(lable);
    
    static int cnt = 0; // 用于记录调用的次数

    int rate = (int)(cur * 100 / total);
    for (int i = 0; i < rate; ++i)
    {
        str[i] = STYLE;
    }
    printf("[%-100s][%d%%][%c]\r", str, rate, lable[cnt % len]);

    ++cnt;
}
